https://leetcode.com/problems/powx-n/
計算平方數值。
利用遞迴概念求出平方值。
double myPow(double x, int n) {
if (n == 0) return 1;
double half = myPow(x, n / 2);
if (n % 2 == 0) return half * half;
else if (n > 0) return half * half * x;
else return half * half / x;
}
var myPow = function(x, n) {
if (n == 0) return 1;
var half = myPow(x, parseInt(n / 2));
if (n % 2 == 0)
{
return half * half;
}
else if (n > 0)
{
return half * half * x;
}
else return
{
half * half / x;
}
};
https://github.com/SIAOYUCHEN/leetcode
https://ithelp.ithome.com.tw/users/20100009/ironman/2500
https://ithelp.ithome.com.tw/users/20113393/ironman/2169
https://ithelp.ithome.com.tw/users/20107480/ironman/2435
https://ithelp.ithome.com.tw/users/20107195/ironman/2382
https://ithelp.ithome.com.tw/users/20119871/ironman/2210
https://ithelp.ithome.com.tw/users/20106426/ironman/2136
You can’t have all that you want, but you can give it all you have got.
你不能樣樣順利,但可以事事盡力